/**
 * Created by steve on 14-9-18.
 */
define(['jquery', 'jquerymobile','dialogs'],function($, m, dia){
    var url_base = 'http://itrufeng.com:8081/staff/';

    return {
        get : function(url, parameters, fail, success) {
            // 链接参数到url
            var full_url = url_base + url + "?";
            var i = 0;
            $.each(parameters, function(key, value){
                if (i == 0) {
                    full_url += key + "=" + value;
                } else {
                    full_url += "&" + key + "=" + value;
                }
            });

            // GET
            $.ajax({
                type: 'GET',
                url: full_url,
                dataType: 'json'
            }).fail(function(error) {
                console.error(error);
                dia.alert('Message', 'Please check your network.', ['Ok'], function(title) {

                });
                fail('Please check your network.');
            }).done(function(response) {
                console.log(response);
                success(response);
            });
        },

        post : function(url, parameters, fail, success) {
            // POST
            $.ajax({
                type: 'POST',
                url: url_base + url,
                dataType: 'json',
                data: parameters
            }).fail(function(error) {
                console.error(error);
                dia.alert('Message', 'Please check your network.', ['Ok'], function(title) {

                });
                fail('Please check your network.');
            }).done(function(response) {
                console.log(response);
                success(response);
            });
        }
    }
});